package pl.msikora.android.lapmagic.database;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class SessionsTable {
	
	private static final String TAG = "SessionsTable";
	
	public static final String TABLE_SESSIONS = "sessions";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_TRACK_ID = "track_id";
	public static final String COLUMN_NAME = "name";
	public static final String COLUMN_DATE = "date";
	
	private static final String TABLE_CREATE = "create table "
			+ TABLE_SESSIONS
			+ "(" 
			+ COLUMN_ID + " integer primary key autoincrement, "
			+ COLUMN_TRACK_ID + " integer, " // references tracks on update cascade
			+ COLUMN_NAME + " text default 'session 1', "
			+ COLUMN_DATE + " text default current_timestamp" // date type in format "YYYY-MM-DD HH:MM:SS" 
			+ ");";
	
	public static void onCreate(SQLiteDatabase database) {
		Log.d(TAG, "creating table sessions with statement '" + TABLE_CREATE
				+ "'");
		database.execSQL(TABLE_CREATE);
	}
	
	public static void onUpgrade(SQLiteDatabase database, int oldVersion, 
			int newVersion) {
		Log.w(TAG, "Upgrading database from version " + oldVersion
				+ " to " + newVersion 
				+ ", which will destroy new all old data");
		database.execSQL("drop table if exists " + TABLE_SESSIONS);
		onCreate(database);
	}

}
